package com.javakc.copyrightin.batch.service;

import com.javakc.commonutils.jpa.base.service.BaseService;
import com.javakc.commonutils.jpa.dynamic.SimpleSpecificationBuilder;
import com.javakc.copyrightin.batch.dao.BatchDao;
import com.javakc.copyrightin.batch.entity.Batch;
import com.javakc.copyrightin.batch.vo.BatchQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.persistence.EntityManager;
import java.util.List;
import java.util.Map;

@Service
public class BatchService extends BaseService<BatchDao,Batch>{
    @Autowired
    private BatchDao batchDao;

    public List<Batch> findBatch(){
        return batchDao.findAll();
    }

//    根据条件进行分页查询
public Page<Batch> findPageBatch(BatchQuery batchQuery, int pageNo , int pageSize) {
    SimpleSpecificationBuilder simpleSpecificationBuilder = new SimpleSpecificationBuilder();
    if(StringUtils.hasLength(batchQuery.getName())){
        simpleSpecificationBuilder.and("name",":",batchQuery.getName());
    }

    Page<Batch> page = dao.findAll(simpleSpecificationBuilder.getSpecification(), PageRequest.of(pageNo - 1,pageSize));
    return page;
}
    public List<Map<Integer,String>> queryFirstSort(){
        return dao.queryFirstSort();
    }

    public List<Map<Integer,String>> querySecondSort(Integer firstId){
        return dao.querySecondSort(firstId);
    }

    public String viewSecondSort(Integer secondId){
        return dao.viewSecondSort(secondId);
    }
}
